import storage from '../cache/gh-storage.js';
import file from '../cache/gh-file.js';
import bus from '../cache/gh-event-bus.js';
import config from '../config/index.js';
import localize from '../i18n/index.js';
import context from '../utils/gh-context/gh-context.js';
import crypto from '../utils/gh-crypto/gh-crypto.js';
import image from '../utils/gh-image/gh-image.js';
import regular from '../utils/gh-regular/gh-regular.js';
import string from '../utils/gh-string/gh-string.js';
import filter from '../utils/gh-filter/gh-filter.js';
import {
  GHHttp as fetch
} from '../net/index';

import {
  wxPromise
} from '../utils/gh-promisify/gh-promisify.js';

const gh = wxPromise();
const utils = {
  context,
  crypto,
  image,
  regular,
  string,
  filter
};
Object.assign(gh, {
  fetch,
  bus,
  storage,
  file,
  config,
  utils
});
let basePageOptions = {
  gh,
  /**
   * 页面的初始数据
   */
  data: {
    localize: localize.getLocalize(context.sysLanguage()),
    filePath: config.FilePath,
    domain: config.Domain
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let pages = getCurrentPages();
    let page = pages[pages.length - 1];
    console.log('++++++++++++++++onShow:' + page.route);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    let pages = getCurrentPages();
    let page = pages[pages.length - 1];
    console.log('++++++++++++++++onHide:' + page.route);
  }
};

export default basePageOptions;